﻿package smooth.core.object.flickrComponent {
	import flash.display.Sprite;
	import smooth.core.object.flickrUserComponent.FlickrUserObject;
	import smooth.core.object.flickrUserComponent.FlickrPhotoInfosLoadedEvent;
	
	// START - 20081123 - LSA
	//public class FlickrImageObject {
	public class FlickrImageObject extends Sprite {
		private var flickrPhotoInfosLoader:FlickrLoader;
		private var flickrPhotoLocationLoader:FlickrLoader;
		private var owner:FlickrUserObject;
		private var flickrImageMetaData:FlickrImageMetadataObject;
		private var localization:FlickrLocalizationObject;
	// END - 20081123 - LSA
		private var server:String;
		private var id:String;
		private var secret:String;
				
		public function FlickrImageObject(server:String, id:String, secret:String) {
			this.server = server;
			this.id = id;
			this.secret = secret;
		}
		
		public function getServer():String {
			return this.server;
		}
		
		public function getId():String {
			return this.id;
		}
		
		public function getSecret():String {
			return this.secret;
		}
		
		// START - 20081123 - LSA
		public function getOwner():FlickrUserObject {
			return this.owner;
		}
		
		public function setOwner(owner:FlickrUserObject):void {
			this.owner = owner;
		}
		
		public function getImageMetaData():FlickrImageMetadataObject {
			return this.flickrImageMetaData;
		}
		
		public function setImageMetaData(flickrImageMetaData:FlickrImageMetadataObject):void {
			this.flickrImageMetaData = flickrImageMetaData;
		}
		
		public function getLocalization():FlickrLocalizationObject {
			return this.localization;
		}
		
		public function setLocalization(localization:FlickrLocalizationObject):void {
			this.localization = localization;
		}
		
		public function loadPhotoInfos():void {
			this.flickrPhotoInfosLoader = new FlickrLoader();
			this.addChild(this.flickrPhotoInfosLoader);
			this.addEventListener("flickrPhotoInfosLoaded", doProcessPhotoInfosLoaded, true, 10, true);
			this.flickrPhotoInfosLoader.getPhotoInfos(this.getId(), this);
		}
		
		public function doProcessPhotoInfosLoaded(e:FlickrPhotoInfosLoadedEvent):void {
			if (e.flickrUserObject != null) {
				this.setOwner(e.flickrUserObject);
			}
			if (e.flickrImageMetaData != null) {
				this.setImageMetaData(e.flickrImageMetaData);
			}
			this.removeChild(this.flickrPhotoInfosLoader);
			this.flickrPhotoInfosLoader = null;
			this.removeEventListener("flickrPhotoInfosLoaded", doProcessPhotoInfosLoaded);
		}
		
		public function loadPhotoLocation():void {
			this.flickrPhotoLocationLoader = new FlickrLoader();
			this.addChild(this.flickrPhotoLocationLoader);
			this.addEventListener("flickrPhotoLocationLoaded", doProcessPhotoLocationLoaded, true, 10, true);
			this.flickrPhotoLocationLoader.getPhotoLocation(this.getId());
		}
		
		public function doProcessPhotoLocationLoaded(e:FlickrPhotoLocationLoadedEvent):void {
			if (e.flickrLocalizationObject != null) {
				this.setLocalization(e.flickrLocalizationObject);
			}
			this.removeChild(this.flickrPhotoLocationLoader);
			this.flickrPhotoLocationLoader = null;
			this.removeEventListener("flickrPhotoLocationLoaded", doProcessPhotoLocationLoaded);
		}
		// END - 20081123 - LSA
	}
	
}